// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GameOver from "./GameOver";

const {ccclass, property} = cc._decorator;

@ccclass
export default class LoadShow extends cc.Component {

    @property(cc.Node)
    one:cc.Node = null;
    @property(cc.Node)
    two:cc.Node = null;

    // onLoad () {}

    start () {
        this.node.zIndex = 10000;
        // this.show();
    }

    //show
    overPage = null;
    show(name?, callback?, state?){
        this.one.runAction(
            cc.sequence(
                cc.scaleTo(0.4, 0.4, 0.4).easing(cc.easeOut(0.5)),
                cc.callFunc(()=>{
                    this.two.active = true;
                    this.two.runAction(
                        cc.sequence(
                            cc.scaleTo(0.1, 0.5, 0.5),
                            cc.scaleTo(0.1, 0.4, 0.4),
                            cc.callFunc(()=>{
                                if(name){
                                    //生成地图
                                    console.log("===============生成地图==================", name);
                                    cc.loader.loadRes("Prefab/" + name,(err, res)=>{
                                        this.scheduleOnce(()=> {
                                            let view = cc.instantiate(res);
                                            // console.log("================view=====================", view);
                                            view.parent = cc.find("Canvas");
                                            if (callback) {
                                                view.getComponent(GameOver).init(state);
                                            }
                                        },0.3)
                                    });
                                }
                            }),
                            cc.delayTime(0.3),
                            cc.callFunc(()=>{
                                this.two.active = false;
                                console.log("===============隐藏小人节点==================");
                                this.one.runAction(
                                    cc.sequence(
                                        cc.scaleTo(0.4, 3, 3).easing(cc.easeOut(0.5)),
                                        cc.callFunc(()=>{
                                            console.log("===============动画执行完成==================");
                                            this.one.destroy();
                                        }),
                                    )
                                )
                            })
                        )
                    )
                }),
            )
        )
    }

    // update (dt) {}
}
